/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * OrderSectionUI.java
 *
 * Created on Nov 1, 2011, 8:30:37 PM
 */
package inventory;

import java.sql.Connection;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JFrame;
import javax.swing.Timer;

/**
 *
 * @author Mark King
 */
public class OrderSectionUI extends javax.swing.JPanel {

    public int width = 680;
    public int height = 354;
            
    public int desktopScreenWidth;
    public int desktopScreenHeight;
    
    public Connection conn;
    public boolean closeWindows=false;
    public JFrame customerOrderFrame;
    public JFrame companyPurchaseFrame;
    public CustomerOrderSectionUI customer;
    public CompanyPurchaseSectionUI company;
    
    public OrderSectionUI(Connection conn, int desktopScreenWidth, int desktopScreenHeight) {
        this.conn = conn;
        this.desktopScreenWidth = desktopScreenWidth;
        this.desktopScreenHeight = desktopScreenHeight;
        initComponents();
    }
    
    @Override
    public int getWidth()
    {
        return width;
    }
    
    @Override
    public int getHeight()
    {
        return height;
    }
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/Promo-icon.png"))); // NOI18N
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                companyPurchaseActionPerformed(evt);
            }
        });

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/sales.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                customerOrderActionPerformed(evt);
            }
        });

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 36)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Order Section");

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel2.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel2.setText("Customer Order Section");

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Company Purchase Section");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(72, 72, 72)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 93, Short.MAX_VALUE)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 211, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(9, 9, 9))
                    .addComponent(jLabel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addGap(84, 84, 84))
            .addGroup(layout.createSequentialGroup()
                .addGap(126, 126, 126)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 425, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(129, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 51, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 33, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(62, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void customerOrderActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_customerOrderActionPerformed
        try{
            customerOrderFrame.dispose();
        }
        catch(Exception e){}
        customerOrderFrame = new JFrame("Customer Order Section");
        customer = new CustomerOrderSectionUI(conn, desktopScreenWidth, desktopScreenHeight);
        customerOrderFrame.add(customer);
        customerOrderFrame.setSize(customer.getWidth(), customer.getHeight());
        customerOrderFrame.setLocation((desktopScreenWidth -customer.getWidth()) /2, (desktopScreenHeight-customer.getHeight())/2);
        customerOrderFrame.setResizable(false);
        customerOrderFrame.setVisible(true);
        ActionListener actionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                try{
                    if(closeWindows || customer.closeWindows){
                        customerOrderFrame.dispose();
                        closeWindows=true;
                        company.closeWindows=true;
                        customer.closeWindows=true;
                    }
                }catch(Exception e){}
            }
        };
        Timer timer = new Timer(0, actionListener);
        timer.start();
    }//GEN-LAST:event_customerOrderActionPerformed

    private void companyPurchaseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_companyPurchaseActionPerformed
        try{
            companyPurchaseFrame.dispose();
        }
        catch(Exception e){}
        companyPurchaseFrame = new JFrame("Company Purchase Section");
        company = new CompanyPurchaseSectionUI(conn, desktopScreenWidth, desktopScreenHeight);
        companyPurchaseFrame.add(company);
        companyPurchaseFrame.setSize(company.getWidth(), company.getHeight());
        companyPurchaseFrame.setLocation((desktopScreenWidth -company.getWidth()) /2, (desktopScreenHeight-company.getHeight())/2);
        companyPurchaseFrame.setResizable(false);
        companyPurchaseFrame.setVisible(true);
        ActionListener actionListener = new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent actionEvent) {
                try{
                    if(closeWindows || company.closeWindows){
                        companyPurchaseFrame.dispose();
                        closeWindows=true;
                        company.closeWindows=true;
                        customer.closeWindows=true;
                    }
                }catch(Exception e){}
            }
        };
        Timer timer = new Timer(0, actionListener);
        timer.start();
    }//GEN-LAST:event_companyPurchaseActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    // End of variables declaration//GEN-END:variables
}
